package biz;

import dao.MemorytbDAO;
import entity.MemorytbEntity;

import java.sql.SQLException;
import java.util.List;

/*
 * @Description：
 *       内存表数据处理
 * @Author: JiangFan
 * @Date: 2019/3/8
 * @Time：15:19
 */
public class MemoryBiz {
    MemorytbDAO md=new MemorytbDAO ();
    /** 添加内存
     * @param me ce由servlet中获取
     * @return
     * @throws SQLException
     * @throws ClassNotFoundException
     */
    public int addMemory(MemorytbEntity me) throws SQLException, ClassNotFoundException {
        MemorytbEntity c=md.selectMemoryOne (me.getMemory_name ());
        return c==null?md.insertMemory (me):0;
    }

    /**查询所有内存信息
     * @return 返回到List集合
     */
    public List<MemorytbEntity> queryMemoryAll ()
            throws ClassNotFoundException, SQLException, InstantiationException, IllegalAccessException {
        return md.selectMemoryAll ();
    }

    /** 查询内存是否可用
     * @param color_name
     * @return 返回true表示内存不存在
     * @throws SQLException
     * @throws ClassNotFoundException
     */
    public boolean checkMemory(String color_name) throws SQLException, ClassNotFoundException {
        return md.selectMemoryOne (color_name)==null;
    }
}
